#include <QApplication>
#include "ElaWindow.h"
#include "ElaApplication.h"
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>

class DashboardPage : public QWidget
{
  public:
    DashboardPage(QWidget* parent = nullptr) : QWidget(parent)
    {
        auto layout = new QVBoxLayout(this);
        auto label = new QLabel("欢迎使用仪表盘", this);
        label->setAlignment(Qt::AlignCenter);
        label->setStyleSheet("font-size: 24px; color: #333;");
        layout->addWidget(label);
    }
};

class SettingsPage : public QWidget
{
  public:
    SettingsPage(QWidget* parent = nullptr) : QWidget(parent)
    {
        auto layout = new QVBoxLayout(this);
        auto label = new QLabel("系统设置页面", this);
        label->setAlignment(Qt::AlignCenter);
        layout->addWidget(label);
    }
};

int main(int argc, char* argv[])
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
    QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);  // 启用高 DPI (界面布局和几何)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);                                               //  启用自动高 DPI 缩放 (图标和图片)
    QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);  // 使用精确的缩放因子，不进行四舍五入
#else
    // 根据实际屏幕缩放比例更改
    qputenv("QT_SCALE_FACTOR", "1.5");
#endif
#endif
    QApplication app(argc, argv);
    eApp->init();  // 初始化资源、字体等
    // eApp->setWindowDisplayMode(ElaApplicationType::ElaMica);

    ElaWindow window;
    window.setWindowTitle("我的应用程序");

    // 创建页面
    auto dashboardPage = new DashboardPage();
    auto settingsPage = new SettingsPage();

    // 添加导航节点
    QString dashboardKey;
    window.addPageNode("仪表盘", dashboardPage, ElaIconType::Alien);

    QString systemKey;
    window.addExpanderNode("系统管理", systemKey, ElaIconType::Acorn);

    QString settingsKey;
    window.addPageNode("基本设置", settingsPage, systemKey, ElaIconType::Gear);

    // 添加底部节点
    QString helpKey;
    window.addFooterNode("帮助", helpKey, 0, ElaIconType::FaceLaughSquint);

    QString aboutKey;
    window.addFooterNode("关于", aboutKey, 0, ElaIconType::CircleBookmark);

    // 设置用户信息
    window.setUserInfoCardVisible(false);
    window.setUserInfoCardTitle("管理员");
    window.setUserInfoCardSubTitle("admin@example.com");


    // 窗口设置
    window.moveToCenter();
    window.show();

    return app.exec();
}